<%@ taglib prefix="p" uri="/WEB-INF/tld/privilege.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%> 
<%response.setHeader("cache-control","public"); %>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>系统用户列表</title>
  <base href="<%=basePath%>"/>
  <%@ include file="../../list_include.jsp"%>
  
  <style type="text/css"> 
	fieldset,table,tr,td {margin:0; padding:0;}
	td {padding:0 5px 0 10px;}
	form label {font-weight:bold;}
	#userTable{margin:5px 0; }
  </style>

  <script type="text/javascript">
	$(document).ready(function() { 
       	$("#userTable").tablesorter({theme:'green', widgets:['zebra', "resizable"]});
       	
       	$("#btn_pageUp").click(function(){
			var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) - 1);
			$("#userForm").submit();
       	});
       	
       	$("#btn_pageDown").click(function(){
       		var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) + 1);
			$("#userForm").submit();
       	});

        $("#btn_insert").click(function(){
            var queryString = $("#userForm").formSerialize();
            queryString = encodeURIComponent(queryString);
            location.href = "<%=basePath%>pjcost/project/insert.do?qs=" + queryString ;
        });
        
        $("#btn_search").click(function(){
            $("#curPage").val(1);
            $("#userForm").submit();
        });

        $("#btn_change").click(function(){
            var page = parseInt($("#selectPage").val());
            var curPage = parseInt($("#curPage").val());
            if(curPage == page) return;
            $("#curPage").val(parseInt(page));
            $("#userForm").submit();
        });
	});  
	
	function resume(id) {
		if(confirm("确定恢复？") != 1) return;
		
		$.get("pjcost/project/resume.do", {id:id}, function(data) {
			var result = $.parseJSON(data);
			if(result.code == 1) {
				alert("恢复成功!");
				$("#userForm").submit();
			} else {
				alert(result.msg);
			}
		});
	}
	
	function deletep(id) {
		if(confirm("确定删除？") != 1) return;
		
		$.get("pjcost/project/delete.do", {id:id}, function(data) {
			var result = $.parseJSON(data);
			if(result.code == 1) {
				alert("删除成功!");
				$("#userForm").submit();
			} else {
				alert(result.msg);
			}
		});
	}
	
	function edit(id) {
        var queryString = $("#userForm").formSerialize();
        queryString = encodeURIComponent(queryString);
        location.href = "<%=basePath%>pjcost/project/update.do?id=" + id + "&qs=" + queryString;
	}
	
  </script>
 </head>

 <body>
  <div>
    <fieldset>
      <legend>查询条件：</legend>
      <form id="userForm" method="post" action="pjcost/project/userList.do">
        <table>
          <tr>
            <td><label for="name">项目名称：</label></td>
            <td><input type="text" name="name" id="name" value="${name}" style="width:150px;" /></td>
            <td><label for="province">省份：</label></td>
            <td><select id="province" name="province" >  
            		<option value="">请选择</option>
           			<c:forEach var="p" items="${provinces}" varStatus="status">
        				<option value="${p.key}" <c:if test="${p.key == province}">selected="selected"</c:if>>${p.value}</option>
        			</c:forEach>
        			</select></td>
        	<td><label for="status">状态：</label></td>
        	<td>
            	<select id="status" name="status" style="width:120px;">
            		<option value="0" <c:if test="${status == 0}">selected="selected"</c:if>>正常</option>
            		<option value="1" <c:if test="${status == 1}">selected="selected"</c:if>>注销</option>
            	</select>
            </td> 
            <td><label for="sort">排序方式：</label></td>
            <td>
            	<select id="sort" name="sort" style="width:130px;">
            		<option value="0" <c:if test="${sort == 0}">selected="selected"</c:if>>按申请时间排序</option>
            		<option value="1" <c:if test="${sort == 1}">selected="selected"</c:if>>按最新回复时间排序</option>
            	</select>
            </td> 
            <td><input type="submit" id="btn_search" name="btn_search" value="查询" style="width:80px;" /></td>
          </tr>
        </table>
        <input type="hidden" name="curPage" id="curPage" value="${curPage}" />
      </form>
    </fieldset>
  </div>
  
  <div>
  	<table id="userTable" class="tablesorter">
	  <thead> 
	    <tr> 
          <th>省份</th>
          <th>项目名称</th> 
          <th>项目编码</th>
	      <th>申请人</th>
	      <th>申报时间</th>
	      <th>状态</th>
	      <th>最新回复时间</th> 
	      <th>操作</th> 
 	    </tr> 
	  </thead>
	  <tbody>
	  <c:forEach var="project" items="${projectList}" varStatus="status">
	  	<tr>
	  	  <td>${provinces[project.province]}</td>
	  	  <td>${project.name}</td>
	  	  <td>${project.code}</td>
	  	  <td> <c:forEach var="user" items="${userList}" varStatus="status">
	  	  	<c:if test="${user.enname == project.applyUser}">
	  	  		${user.cnname}
	  	  	</c:if>
	  	  </c:forEach></td>
	  	  <td>${project.applyTime}</td>
	  	  <td>
	  	  	<c:if test="${project.status == 0 }">正常</c:if>
            <c:if test="${project.status == 1 }">注销</c:if> 
            </td>
	  	  <td>
	  	  <c:forEach var="maxDate" items="${maxDateList}" varStatus="status">
	  	  	<c:if test="${maxDate.objectId == project.id}">
	  	  		${maxDate.createTime}
	  	  	</c:if>
	  	  </c:forEach>
	  	  </td>
	  	  <td>
	  	  	<p:chkPri actionUrl="pjcost/project/update.do"><a href=# onclick="javascript:edit('${project.id}'); return false;">修改</a></p:chkPri>
	  	  	<c:if test="${project.status == 0}">
              <p:chkPri actionUrl="pjcost/project/delete.do"><a href=# onclick="javascript:deletep('${project.id}'); return false;">删除</a></p:chkPri>
            </c:if>
            <c:if test="${project.status != 0}">
              <p:chkPri actionUrl="pjcost/project/resume.do"><a href=# onclick="javascript:resume('${project.id}'); return false;">恢复</a></p:chkPri>
            </c:if>	
	  	  </td>
	  	</tr>
	  	</c:forEach>
	  </tbody>
  	</table>
  </div>

  <div>
      <div style="float:left;">
        <input id="btn_insert" type="submit" value="新增" />
      </div>

      <div style="text-align:right;">
        <c:if test="${curPage <= 1}"><input type="button" disabled="disabled" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage > 1}"><input type="button" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage >= totalPage}"><input type="button" id="btn_pageDown" disabled="disabled" value="下一页"/></c:if>
        <c:if test="${curPage < totalPage}"><input type="button" id="btn_pageDown" value="下一页"/></c:if>
        共${totalPage}页/共${totalRecords}条
        <select id="selectPage" style="width: auto;">
            <c:forEach var="i" begin="1" end="${totalPage}">
                <option id="${i}" <c:if test="${i == curPage}">selected="selected"</c:if>>${i}</option>
            </c:forEach>
        </select>
        <input id="btn_change" type="button" value="转至" />
      </div>
  </div>
 </body>
</html>

